package com.employment.controller;

import com.employment.dto.Result;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.time.LocalDateTime;
import java.util.HashMap;
import java.util.Map;

/**
 * 公共API控制器
 * 
 * @author Employment System
 * @since 1.0.0
 */
@Tag(name = "公共接口", description = "公共API接口")
@RestController
@RequestMapping("/api/public")
@RequiredArgsConstructor
public class PublicController {

    @Operation(summary = "系统信息", description = "获取系统基本信息")
    @GetMapping("/info")
    public Result<Map<String, Object>> getSystemInfo() {
        Map<String, Object> info = new HashMap<>();
        info.put("name", "招聘系统");
        info.put("version", "1.0.0");
        info.put("description", "类Boss直聘的招聘平台系统");
        info.put("author", "Employment System");
        info.put("serverTime", LocalDateTime.now());
        
        return Result.success(info);
    }

    @Operation(summary = "健康检查", description = "系统健康状态检查")
    @GetMapping("/health")
    public Result<Map<String, Object>> healthCheck() {
        Map<String, Object> health = new HashMap<>();
        health.put("status", "UP");
        health.put("timestamp", LocalDateTime.now());
        health.put("uptime", System.currentTimeMillis());
        
        return Result.success(health);
    }

    @Operation(summary = "系统配置", description = "获取系统公开配置")
    @GetMapping("/config")
    public Result<Map<String, Object>> getPublicConfig() {
        Map<String, Object> config = new HashMap<>();
        config.put("siteName", "招聘系统");
        config.put("siteTitle", "招聘系统 - 类Boss直聘平台");
        config.put("siteKeywords", "招聘,求职,Boss直聘,招聘网站,人力资源");
        config.put("siteDescription", "专业的招聘求职平台，为企业和求职者提供高效的双向匹配服务");
        config.put("maxFileSize", "10MB");
        config.put("allowedFileTypes", new String[]{"jpg", "jpeg", "png", "gif", "pdf", "doc", "docx"});
        
        return Result.success(config);
    }

    @Operation(summary = "数据字典", description = "获取系统数据字典")
    @GetMapping("/dict")
    public Result<Map<String, Object>> getDataDictionary() {
        Map<String, Object> dict = new HashMap<>();
        
        // 用户类型
        Map<String, String> userTypes = new HashMap<>();
        userTypes.put("1", "求职者");
        userTypes.put("2", "企业用户");
        userTypes.put("3", "管理员");
        dict.put("userType", userTypes);
        
        // 性别
        Map<String, String> genders = new HashMap<>();
        genders.put("0", "女");
        genders.put("1", "男");
        dict.put("gender", genders);
        
        // 工作类型
        Map<String, String> workTypes = new HashMap<>();
        workTypes.put("1", "全职");
        workTypes.put("2", "兼职");
        workTypes.put("3", "实习");
        workTypes.put("4", "远程");
        dict.put("workType", workTypes);
        
        // 薪资类型
        Map<String, String> salaryTypes = new HashMap<>();
        salaryTypes.put("1", "月薪");
        salaryTypes.put("2", "年薪");
        salaryTypes.put("3", "日薪");
        salaryTypes.put("4", "时薪");
        dict.put("salaryType", salaryTypes);
        
        // 职位状态
        Map<String, String> jobStatus = new HashMap<>();
        jobStatus.put("0", "下线");
        jobStatus.put("1", "招聘中");
        jobStatus.put("2", "已暂停");
        jobStatus.put("3", "已结束");
        dict.put("jobStatus", jobStatus);
        
        // 申请状态
        Map<String, String> applicationStatus = new HashMap<>();
        applicationStatus.put("1", "待查看");
        applicationStatus.put("2", "已查看");
        applicationStatus.put("3", "面试邀请");
        applicationStatus.put("4", "面试中");
        applicationStatus.put("5", "已录用");
        applicationStatus.put("6", "已拒绝");
        applicationStatus.put("7", "已撤回");
        dict.put("applicationStatus", applicationStatus);
        
        // 学历
        Map<String, String> education = new HashMap<>();
        education.put("primary", "小学");
        education.put("middle", "初中");
        education.put("high", "高中");
        education.put("college", "大专");
        education.put("bachelor", "本科");
        education.put("master", "硕士");
        education.put("doctor", "博士");
        dict.put("education", education);
        
        // 工作经验
        Map<String, String> workExperience = new HashMap<>();
        workExperience.put("0", "无经验");
        workExperience.put("1", "1年以下");
        workExperience.put("1-3", "1-3年");
        workExperience.put("3-5", "3-5年");
        workExperience.put("5-10", "5-10年");
        workExperience.put("10+", "10年以上");
        dict.put("workExperience", workExperience);
        
        return Result.success(dict);
    }

    @Operation(summary = "城市列表", description = "获取支持的城市列表")
    @GetMapping("/cities")
    public Result<Map<String, Object>> getCities() {
        Map<String, Object> cities = new HashMap<>();
        
        // 热门城市
        String[] hotCities = {"北京", "上海", "广州", "深圳", "杭州", "南京", "武汉", "成都", "西安", "重庆"};
        cities.put("hot", hotCities);
        
        // 按首字母分组的城市
        Map<String, String[]> cityGroups = new HashMap<>();
        cityGroups.put("A", new String[]{"阿克苏", "阿拉善", "阿勒泰", "安康", "安庆", "鞍山", "安顺", "安阳"});
        cityGroups.put("B", new String[]{"北京", "包头", "保定", "宝鸡", "保山", "巴中", "北海", "蚌埠"});
        cityGroups.put("C", new String[]{"重庆", "成都", "长沙", "长春", "常州", "沧州", "承德", "赤峰"});
        cityGroups.put("D", new String[]{"大连", "东莞", "大庆", "丹东", "大同", "大理", "德阳", "德州"});
        // ... 可以继续添加更多城市
        cities.put("groups", cityGroups);
        
        return Result.success(cities);
    }

    @Operation(summary = "行业列表", description = "获取支持的行业列表")
    @GetMapping("/industries")
    public Result<String[]> getIndustries() {
        String[] industries = {
                "互联网/电子商务", "金融/投资/证券", "教育/培训", "医疗/制药/生物",
                "制造业", "房地产/建筑", "零售/贸易", "媒体/广告/文化",
                "物流/运输", "政府/事业单位", "能源/化工", "农林牧渔",
                "旅游/酒店/餐饮", "法律/咨询", "体育/娱乐", "其他行业"
        };
        
        return Result.success(industries);
    }

    @Operation(summary = "职位类别", description = "获取职位类别列表")
    @GetMapping("/job-categories")
    public Result<Map<String, Object>> getJobCategories() {
        Map<String, Object> categories = new HashMap<>();
        
        // 技术开发
        Map<String, String[]> tech = new HashMap<>();
        tech.put("前端开发", new String[]{"JavaScript", "Vue.js", "React", "Angular"});
        tech.put("后端开发", new String[]{"Java", "Python", "Go", "Node.js"});
        tech.put("移动开发", new String[]{"Android", "iOS", "Flutter", "React Native"});
        tech.put("测试", new String[]{"功能测试", "自动化测试", "性能测试", "安全测试"});
        tech.put("运维", new String[]{"Linux运维", "云计算", "DevOps", "网络安全"});
        categories.put("技术开发", tech);
        
        // 产品设计
        Map<String, String[]> product = new HashMap<>();
        product.put("产品经理", new String[]{"产品规划", "需求分析", "用户研究", "数据分析"});
        product.put("UI设计", new String[]{"界面设计", "交互设计", "用户体验", "视觉设计"});
        categories.put("产品设计", product);
        
        // 市场营销
        Map<String, String[]> marketing = new HashMap<>();
        marketing.put("市场推广", new String[]{"品牌推广", "活动策划", "内容营销", "新媒体运营"});
        marketing.put("销售", new String[]{"销售代表", "销售经理", "客户经理", "渠道销售"});
        categories.put("市场营销", marketing);
        
        return Result.success(categories);
    }
}